package com.generater;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.zaxxer.hikari.metrics.MetricsTrackerFactory;
import org.junit.jupiter.api.Test;

import java.nio.file.Paths;

/**
 * @author zhangning
 * @since 2025/2/26 11:13
 */

public class NewCodeGenerator {

    private static final String USERNAME = "root";
    private static final String PASSWORD = "123456";
    private static final String URL = "jdbc:mysql://localhost:3306/ConstructionDB?useUnicode=true&characterEncoding=utf8&useSSL=false";
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String PROJECT_PATH = "D:\\develop\\IdeaProjects\\demo1";

    private static final String[] TABLES = {"T_flow_step_def"};


    @Test
    public void codeGenerator(){

        FastAutoGenerator.create(URL, USERNAME, PASSWORD)
                .globalConfig(builder -> builder
                        .author("ZhangNing")
                        .outputDir(PROJECT_PATH + "/src/main/java/generator")
                        .commentDate("yyyy-MM-dd")
                        .enableSwagger()  // 开启 Swagger 模式
                )
                .packageConfig(builder -> builder
                        .parent("com.crud")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> {
                    builder.addInclude(TABLES)// 需要生成的表名
                            .entityBuilder()
                            .enableLombok() // 启用 Lombok
                            .enableTableFieldAnnotation() // 启用字段注解
                            .controllerBuilder()
                            .enableRestStyle() // 启用 REST 风格
                            .mapperBuilder()
                            .enableBaseResultMap() // 启用 BaseResultMap 生成
                            .enableBaseColumnList(); // 启用 BaseColumnList
                        }
                )
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
}